#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++) 
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-', ch = getchar(); 
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x;
}

const int N = 3e5 + 10;

int n, q, ans[N], a[N];
veg pot[N];

namespace T {
	int tr[N];
	void add(int x, int v) { for(; x <= n; x += x &- x) tr[x] += v; }
	int query(int x) { int res = 0; for(; x; x -= x & -x) res += tr[x]; return res; }
	int get(int k) {
		int x = 0;
		per(i, 18, 0) {
			if((x | 1 << i) <= n && tr[x | 1 << i] < k) x |= 1 << i, k -= tr[x];
		} return x;
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; q = in; rep(i, 1, n) a[i] = i - in;
	rep(i, 1, q) {
		int l = in + 1, r = n - in;
		pot[r].pb({ l, i });
	}
	rep(i, 1, n) {
		int pos = 0;
		if(a[i] < 0) pos = 1;
		else pos = min(T :: get(i - a[i]), i) + 1;
		T :: add(pos, 1);
		for(auto d : pot[i]) ans[d.se] = i - T :: query(d.fi);
	} rep(i, 1, q) printf("%d\n", ans[i]);
	return 0;
}
